<?php

namespace StudyBuddy\Controllers;

use \StudyBuddy\Responder;

/**
 * This controller processes Ajax requests only
 * requests are for sorted and/or paginaged block
 * with user answers or user questions
 *
 */
class Userinfotab extends Userinfo
{


	protected function main(){
		$this->getUser();
		$tab = $this->oRequest->get('tab');
		if('q' === $tab){
			return $this->getQuestions();
		}

		return $this->getAnswers();
	}

	/**
	 * Get content of sorted and paginated User Questions
	 * block and return in via XHR
	 *
	 */
	protected function getQuestions(){
		$s = \StudyBuddy\UserQuestions::get($this->oRegistry, $this->oUser);
		Responder::sendJSON(array('replace' => array('target' => 'uquestions', 'content' => $s) ));
	}


	/**
	 * Get paginated and sorted block with user
	 * Answers and returl via XHR
	 *
	 */
	protected function getAnswers(){
		d('getting answers block');
		$s = \StudyBuddy\UserAnswers::get($this->oRegistry, $this->oUser);
		Responder::sendJSON(array('replace' => array('target' => 'useranswers', 'content' => $s) ));
	}

}
